<!-- 商品分类 -->
<template>
  <div class="goods-category">
    <div class="goods-category-box">
      <div class="header">分类列表</div>
      <div class="btn-box">
        <el-button size="small" type="primary" @click="addCate">添加分类</el-button>
      </div>
      <div class="body">
        <el-table :data="goodsCategoryList" style="width: 100%">
          <el-table-column label="#" width="80" type="index"></el-table-column>
          <el-table-column label="PID" width="100">
            <template slot-scope="scope">
              <span>{{ scope.row.pid }}</span>
            </template>
          </el-table-column>
          <el-table-column label="分类名称" width="180">
            <template slot-scope="scope">
              <span>{{ scope.row.cate_name }}</span>
            </template>
          </el-table-column>
          <el-table-column label="分类图标" width="180">
            <template slot-scope="scope">
              <span>{{ scope.row.pic?scope.row.pic:'暂无图片' }}</span>
            </template>
          </el-table-column>
          <el-table-column label="排序" width="100">
            <template slot-scope="scope">
              <span>{{ scope.row.sort }}</span>
            </template>
          </el-table-column>
          <el-table-column label="添加时间" width="200">
            <template slot-scope="scope">
              <span>{{ scope.row.add_time }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button size="mini" @click="goodsCateEdit(scope.$index, scope.row)">编辑</el-button>
              <el-button
                size="mini"
                type="danger"
                @click="goodsCateDelete(scope.$index, scope.row)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  inject: ["reload"],
  data() {
    return {
      formInline: {
        txt: "",
        menu: "",
        show: ""
      },
      allMenus: ["休闲食品", "干果干货", "豆制品类", "海鲜制品"],
      goodsCategoryList: []
    };
  },
  created() {
    this.$http.getGoodsCategory().then(res => {
      // console.log(res);
      if (res && res.data.code === 200) {
        this.goodsCategoryList = res.data.data;
      }
    });
  },
  methods: {
    addCate(){
      console.log()
    },
    goodsCateEdit() {
      
    },
    goodsCateDelete(index, item) {
      this.$confirm("此操作将删除该分类, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http.removeGoodsCategory({ id: item.id }).then(res => {
            // console.log(res);
            if (res && res.data.code == 200) {
              this.$message({
                type: "success",
                message: "删除成功!"
              });
              this.reload();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  }
};
</script>

<style scoped lang="less">
.goods-category {
  .goods-category-box {
    background: #fff;
    // margin: 8px;
    border-radius: 2px;
  }
  .goods-category-box {
    // margin-top:18px;
    .btn-box {
      padding-top: 10px;
      padding-left: 15px;
    }
  }
  .header {
    position: relative;
    height: 42px;
    line-height: 42px;
    padding: 0 15px;
    border-bottom: 1px solid #f6f6f6;
    color: #333;
    font-size: 14px;
  }
  .body {
    padding: 10px 20px 20px 20px;
  }
}
</style>
